#include "ink_screen_platform_io.h"
#include "driver/gpio.h"
#include "driver/spi_master.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

extern spi_device_handle_t spidev;

void ink_screen_delay_ms(uint32_t ms)
{
    // 延时 ms
    vTaskDelay(ms);
}

void ink_screen_spi_write_bytes(uint8_t *data, uint32_t len)
{
    // 写入 len 字节的 data
    // spi_write_bytes(data, len);
    spi_transaction_t t = {
        .length = len * 8, // Len is in bytes, transaction length is in bits.
        .tx_buffer = data, // Data
    };
    
    // spi_device_transmit(spidev, &t);
    spi_device_polling_transmit(spidev, &t);
}

void ink_screen_gpio_mode(gpio_num_t gpio, uint8_t mode)
{
    // 设置 gpio 的模式
    gpio_set_direction(gpio, mode == INK_SCREEN_GPIO_MODE_OUTPUT ? GPIO_MODE_OUTPUT : GPIO_MODE_INPUT);
}

void ink_screen_spi_init(void)
{
}
